var request = require('supertest'),
    express = require('express');
var chai = require('chai');
var should = chai.should();
var assert = chai.assert;

var app = request('http://localhost:4000');

//首先要登录系统,记录登录后的cookies
var COOKIE = null;
before(function(done) {

    this.timeout(4000);
    app.post('/login/matchCode')
        .send({
            userName: 'jigi',
            password: '123'
        })
        .expect(200)
        .end(function(err, res) {
            res.body.should.equal(true);
            console.log(res.headers['set-cookie']);
            COOKIE = res.headers['set-cookie'].map(function(item) {
                return item.split(';')[0];
            }).join(';');
            done();
        });
});

describe('#project 测试', function() {
    it('应该能够获取到该用户的所有项目', function(done) {
        this.timeout(4000);
        console.log(COOKIE);
        app
            .get('/project')
            .set('Accept', 'application/json')
            .set('Cookie', COOKIE)
            .expect(200)
            .end(function(err, res) {
                should.not.exist(err);
                assert.equal(res.body.length > 0, true);
                // console.log(JSON.stringify(res.body));
                done();
            });
    });
});


describe('#审核项目统计测试', function() {
    it('应该能够统计待审核的项目', function(done) {
        this.timeout(12000000);
        var activity = require('./../activity/handler/newDataUpload.js');
        activity({
            prjId: 525,
            date: "2014-9-30"
        }).then(function() {
            done();
        });
    });
});


describe('#获取统计的审核项目', function() {
    it('应该能够获取用户名下的待审核的项目', function(done) {
        this.timeout(12000000);
        var User = require('./../models/User.js');
        var user = new User();
        user.userName = "jigi";

        user.getReviewProjectList().then(function(data) {
            console.log(data);
            done();
        });
    });
});

//

describe('#获取某一个项目某一类型某一个位置某一天的未审核数据', function() {
    it.only('应该能够正确获取数据,并且是JSON格式', function(done) {
        this.timeout(12000000);
        var req = require('request');
        req({
            method: 'get',
            url: "http://localhost:4909/api/ReviewRecentChanges?prjid=58&location=%E4%B8%8A%E8%A1%8C%E7%BA%BF&monitorType=%E6%B2%89%E9%99%8D&date=2015-03-23"
        }, function(err, res, body) {
            console.log(body);
            done();
        });
    });
});
